package com.cq.androidtools.view.table

import android.content.Context
import android.util.AttributeSet
import android.view.MotionEvent
import android.view.View

/**
 * 作者: CQ
 * 日期: 2021-09-02
 * 说明:
 */
class ExView @JvmOverloads constructor(
    context: Context, attrs: AttributeSet? = null, defStyleAttr: Int = 0,
) : View(context, attrs, defStyleAttr) {
    var x = 0
    var y = 0
    override fun onTouchEvent(event: MotionEvent?): Boolean {


        when (event!!.action) {
            MotionEvent.ACTION_DOWN -> {
                x = event.x.toInt()
                y = event.y.toInt()
            }

            MotionEvent.ACTION_MOVE -> {
                val offsetX = x - event.x.toInt();
                val offsetY = y - event.y.toInt();
                layout(left - offsetX, top - offsetY, right - offsetX, bottom - offsetY);
            }
        }
        return super.onTouchEvent(event)
    }

}